package com.springboot.usercenter.model.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-04-25
 * Time: 14:05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private ResultCodeEnum code;
    private T data;
    private String message;

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCodeEnum.SUCCESS, data, "");
    }

    public static <T> Result<T> success(T data, String message) {
        Result<T> result = success(data);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> error(String message) {
        return new Result<>(ResultCodeEnum.ERROR, null, message);
    }

    public static <T> Result<T> serverError() {
        return new Result<>(ResultCodeEnum.SERVER_ERROR,
                null, "系统错误，请联系管理员");
    }
}
